Passive pruning of filters in a convolutional neural network

ABSTRACT

Methods and systems for pruning a convolutional neural network (CNN) include calculating a sum of weights for each filter in a layer of the CNN. The filters in the layer are sorted by respective sums of weights. A set of m filters with the smallest sums of weights is filtered to decrease a computational cost of operating the CNN. The pruned CNN is retrained to repair accuracy loss that results from pruning the filters.

RELATED APPLICATION INFORMATION

This application claims priority to U.S. Patent Application No.62/338,031, filed on May 18, 2016, and 62/338,797, filed on May 19,2016, incorporated herein by reference in its entirety. This applicationis related to an application entitled, “SECURITY SYSTEM USING ACONVOLUTIONAL NEURAL NETWORK WITH PRUNED FILTERS,” Ser. No. 15/590,666,which is incorporated by reference herein in its entirety.

BACKGROUND Technical Field

The present invention relates to neural networks and, more particularly,to filter pruning in convolutional neural networks.

Description of the Related Art

As convolutional neural networks (CNNs) grow deeper (i.e., involveprogressively more layers), the cost of computing inferences increaseswith the number of parameters and convolution operations involved. Thesecomputational costs are particularly relevant when dealing with embeddedsensors and mobile devices where computational and power resources arelimited. High inference costs post a similar barrier in contexts wherehigh responsiveness and low latency are needed.

Existing approaches to reducing the storage and computation costsinvolve model compression by pruning weights with small magnitudes andthen retraining the model. However, pruning parameters does notnecessarily reduce computation time, because the computation cost islow. In addition, the resulting sparse models lack optimizations thatmake computations practical.

SUMMARY

A method for pruning a convolutional neural network (CNN) includescalculating a sum of weights for each filter in a layer of the CNN. Thefilters in the layer are sorted by respective sums of weights. A set ofm filters with the smallest sums of weights is pruned to decrease acomputational cost of operating the CNN. The pruned CNN is retrained torepair accuracy loss that results from pruning the filters.

A method for pruning a CNN includes calculating a sum of weights foreach filter in a layer of the CNN. The filters in the layer are sortedby respective sums of weights. A number of filters m is selected basedon a sensitivity of the layer to pruning, measured as a degree ofaccuracy change. A set of m filters with the smallest sums of weights ispruned to decrease a computational cost of operating the CNN. Featuremaps corresponding to the m pruned filters are pruned. Kernels in asubsequent layer that correspond to the pruned feature maps are pruned.The pruned CNN are retrained to repair accuracy loss that results frompruning the filters.

A system for pruning a CNN includes a pruning module having a processorconfigured to calculate a sum of weights for each filter in a layer ofthe CNN, to sort the filters in the layer by respective sums of weights,and to prune m filters with the smallest sums of weights to decrease acomputational cost of operating the CNN. A training module is configuredto retrain the pruned CNN to repair accuracy loss that results frompruning the filters.

These and other features and advantages will become apparent from thefollowing detailed description of illustrative embodiments thereof,which is to be read in connection with the accompanying drawings.

BRIEF DESCRIPTION OF DRAWINGS

The disclosure will provide details in the following description ofpreferred embodiments with reference to the following figures wherein:

FIG. 1 is a diagram showing the correspondence between an input,filters, and feature maps in a convolutional neural network (CNN) systemin accordance with the present embodiments;

FIG. 2 is a block/flow diagram of a method for pruning filters from aCNN in accordance with the present embodiments;

FIG. 3 is a CNN system that includes filter pruning in accordance withthe present embodiments; and

FIG. 4 is a security system based on pruned CNN classifiers inaccordance with the present embodiments.

DETAILED DESCRIPTION OF PREFERRED EMBODIMENTS

In accordance with the present principles, systems and methods areprovided for passive pruning of filters in convolutional neural networks(CNNs). Rather than pruning parameters, the present embodiments reducethe computational cost of trained CNNs by pruning filters. Pruningfilters does not introduce sparsity and therefore does not necessitatethe use of sparse libraries or specialized hardware. The number offilters that are pruned correlates directly with computationalacceleration by reducing the number of matrix multiplications. Inaddition, instead of layer-wise iterative fine-tuning, one-shot pruningand retaining may be used to save retraining time when pruning filtersacross multiple layers.

CNNs are extensively used in image and video recognition, naturallanguage processing, and other machine learning processes. CNNs usemulti-dimensional layers of weights to create filters that have smallspatial coverage but that extend through the full depth of an inputvolume. To use the example of an image input, the individual pixelsrepresent the width and height of the input, while the number of colors(e.g., red, green, and blue) represent the depth. Thus, a filter in aCNN being used to process image data would apply to a limited number ofpixels but would apply to all of the color information for those pixels.The filter is convolved across the width and height of the input volume,with dot products being calculated between entries of the filter and theinput at each position.

The present embodiments prune low-magnitude convolutional filters andthose that are not activated frequently (i.e., filters which have a lowabsolute magnitude of weights) from the CNN. Convolutional filters thatare infrequently activated are driven down to zero. This results in anefficient network that involves fewer convolutional operations.

Referring now in detail to the figures in which like numerals representthe same or similar elements and initially to FIG. 1, a diagram of thesteps performed in a CNN calculation is shown. The input volume 102 mayrepresent, for example, an image, a frame of video, a document, or anyother appropriate set of multi-dimensional input data. Each of a set offilters is convolved with the entire input volume 102 to generatefeature maps 106. Depending on the weights of the filters 104, thefilters 104 may be low in magnitude and can generate feature maps withlimited activations.

In the example of FIG. 1, the third filter 108 is a low-magnitudefilter. This low-magnitude filter 108 produces a feature map 110 thathas limited activations. By the present embodiments, low-magnitudefilters 108 may be removed. This cuts down substantially on thecomputational cost of using the CNN, while the loss of the weak featuremaps 110 will not significantly affect the outcome.

Let n_(i) denote the number of input channels for the i^(th)convolutional layer of a CNN. The height and width of the input featuremaps are denoted as h_(i) and w_(i) respectively. The convolutionallayer transforms the input feature maps x_(i)∈

^(n) ^(i) ^(×h) ^(i) ^(×w) ^(i) into the output feature maps x_(i+1)

^(n) ^(i+1) ^(×h) ^(i+1) ^(×w) ^(i+1) , which are used as input featuremaps for the next convolutional layer. This is achieved by applyingn_(i+1) 3D filters

_(i,j)∈

^(n) ^(i) ^(×k×k) on the n_(i) input channels, in which one filtergenerates one feature map.

Each filter is formed from n_(i) 2D kernels

∈

^(k×k). All of the filters together form the kernel matrix

∈

^(n) ^(i) ^(×n) ^(i+1) ^(×k×k). The number of operations of theconvolutional layer is then n_(i+1)n_(i)k²h_(i+1)w_(i+1). When a filter

_(i,j) is pruned, the corresponding filter map x_(i+1,j) is removed(e.g., when filter 108 is pruned, feature map 110 is removed). Thisreduces the number of operations by n_(i)k²h_(i+1)w_(i+1). The kernelsthat apply to the removed feature maps 110 from the filters of the nextconvolutional layer are also removed, saving an additionaln_(i+2)k²h_(i+2)w_(i+2) operations. Pruning m filters from layer i willreduce m/n_(i+1) of the computation cost for layers i and i+1.

Referring now to FIG. 2, a method for pruning a CNN is shown. Thepresent embodiments prune the less useful filters 108 from awell-trained model to increase computational efficiency with a minimalaccuracy drop. The relative importance of the filters 104 in each layeris measured by calculating the sum of each filter's absolute weights: Σ|

_(ij)|, otherwise written herein as the l₁-norm, ∥

_(ij)∥₁. Since the number of input channels n_(i) is the same across allfilters, Σ|

_(i,j)| also represents the average magnitude of its kernel weights.This value gives an expectation of the magnitude of the output featuremap.

Filters 108 with smaller kernel weights tent to produce feature maps 110with weak activations as compared to the other filters 104 in thatlayer. It has been shown experimentally that pruning the smallestfilters works better that pruning the same number of random filters orselecting the largest filters. Compared to other criteria foractivation-based feature map pruning, the l₁-norm is a good criterionfor data-free filter selection.

Thus, for each filter 104, block 202 calculates the sum of its absolutekernel weights as s_(j)=Σ_(l=1) ^(n) ¹ Σ|

|. Block 204 sorts the filters 104 according to their summed kernelweights s_(j). Block 206 then prunes the m filters 108 with the smallestvalues for s_(j). Block 208 prunes the feature maps 110 corresponding tothe m pruned filters, and block 210 prunes the filters from the nextconvolutional layer corresponding to the pruned feature maps 110. Block212 then creates a new kernel matrix for both layer i and layer i+1 andblock 214 copies the remaining kernel weights to the new model.

Pruning filters with low absolute weights sums is distinct from pruningfilters based solely on low-magnitudes. Magnitude-based weight pruningmay prune away whole filters when all of the kernel weights of a filterare lower than a given threshold. Magnitude-based weight pruning needscareful tuning of its threshold and it is difficult to predict thenumber of filters that will eventually be pruned in that process.

To understand the sensitivity of each layer to pruning, each layer ispruned independently and evaluated with respect to the pruned network'saccuracy. Some layers that maintain their accuracy as filters are prunedaway, while other layers are more sensitive to pruning and would loseaccuracy. For deep CNNs, layers in the same stage (e.g., with the samefeature map size) have a similar sensitivity to pruning. To avoidintroducing layer-wise meta-parameters, the same pruning ratio is usedfor all layers in a given stage. For layers that are sensitive topruning, a smaller percentage of the filters are pruned. In some cases,pruning may be skipped entirely for particularly sensitive layers.

The present embodiments prune filters from multiple layers at once. Fordeep networks, pruning and retraining on a layer-by-layer basis can bevery time consuming. Pruning layers across the network gives a holisticview of the robustness of the network, resulting in a smaller network.In particular, a “greedy” pruning accounts for filters that have beenremoved in previous layers without considering the kernels for thepreviously pruned feature maps when calculating the sum of absoluteweights. In contrast, an “independent” pruning determines which filtersshould be pruned at each layer, independent of other layers. The greedyapproach, while not globally optimal, is holistic and results in prunednetworks with higher accuracy, particularly when many filters arepruned.

For simpler CNNs, any of the filters in any convolutional layer can beeasily pruned. However, for complex network architectures, pruning maynot be straightforward. Complex architectures may impose restrictions,such that filters need to be pruned carefully. In one example,correspondences between feature maps may necessitate the pruning offeature maps to permit pruning of a given convolutional layer.

After pruning, performance degradation should be corrected by retrainingthe CNN. Two strategies for pruning filters across multiple layersinclude, “prune once and retrain,” and, “prune and retrain iteratively.”In “prune once and retrain,” filters of multiple layers are pruned asingle time and are retrained until the original accuracy is restored.In “prune and retrain iteratively,” filters are pruned layer-by-layer orfilter-by-filter and then iteratively retrained. The model is retrainedbefore pruning the next layer, allowing the weights to adapt to thechanges from the pruning process.

For layers that are resilient to pruning, the “prune once and retrain”strategy can be used to prune away significant portions of the network,with any loss in accuracy being regained by retraining for even a shortperiod of time. When some filters from the sensitive layers are prunedaway, or when large portions of the network are pruned away, it may notbe possible to recover the original accuracy. Iterative pruning andretraining may yield better results, but the iterative process can takeup much more time, particularly for deep networks.

Embodiments described herein may be entirely hardware, entirely softwareor including both hardware and software elements. In a preferredembodiment, the present invention is implemented in software, whichincludes but is not limited to firmware, resident software, microcode,etc.

Embodiments may include a computer program product accessible from acomputer-usable or computer-readable medium providing program code foruse by or in connection with a computer or any instruction executionsystem. A computer-usable or computer readable medium may include anyapparatus that stores, communicates, propagates, or transports theprogram for use by or in connection with the instruction executionsystem, apparatus, or device. The medium can be magnetic, optical,electronic, electromagnetic, infrared, or semiconductor system (orapparatus or device) or a propagation medium. The medium may include acomputer-readable storage medium such as a semiconductor or solid statememory, magnetic tape, a removable computer diskette, a random accessmemory (RAM), a read-only memory (ROM), a rigid magnetic disk and anoptical disk, etc.

Each computer program may be tangibly stored in a machine-readablestorage media or device (e.g., program memory or magnetic disk) readableby a general or special purpose programmable computer, for configuringand controlling operation of a computer when the storage media or deviceis read by the computer to perform the procedures described herein. Theinventive system may also be considered to be embodied in acomputer-readable storage medium, configured with a computer program,where the storage medium so configured causes a computer to operate in aspecific and predefined manner to perform the functions describedherein.

A data processing system suitable for storing and/or executing programcode may include at least one processor coupled directly or indirectlyto memory elements through a system bus. The memory elements can includelocal memory employed during actual execution of the program code, bulkstorage, and cache memories which provide temporary storage of at leastsome program code to reduce the number of times code is retrieved frombulk storage during execution. Input/output or I/O devices (includingbut not limited to keyboards, displays, pointing devices, etc.) may becoupled to the system either directly or through intervening I/Ocontrollers.

Network adapters may also be coupled to the system to enable the dataprocessing system to become coupled to other data processing systems orremote printers or storage devices through intervening private or publicnetworks. Modems, cable modem and Ethernet cards are just a few of thecurrently available types of network adapters.

Referring now to FIG. 3, a CNN system 300 is shown. The system 300includes a hardware processor 302 and memory 304. A CNN 306 isimplemented either in hardware or in software. The CNN 306 takes inputdata and generates an output based on the filters and weights that makeup the CNN's configuration. The system 300 furthermore includes one ormore functional modules that may, in some embodiments, be implemented assoftware that is stored in the memory 304 and executed by hardwareprocessor 302. In alternative embodiments, the functional modules may beimplemented as one or more discrete hardware components in the form of,e.g., application specific integrated chips or field programmable gatearrays.

In particular, a training module 308 trains the CNN 306 based ontraining data. The training data includes one set of data used to trainthe CNN 306 and another set of data used to test the CNN 306, withdifferences between the outcome of the 306 and expected outcome from thetesting data being used to adjust the CNN 306. A pruning module 310prunes filters from the CNN 306 to reduce the computational complexity.The training module 308 and the pruning module 310 work together asdescribed above, either in a prune-once implementation or in aniterative implementation, to ensure that the output of the CNN 306 isnot significantly degraded by pruning.

Referring now to FIG. 4, a security system 400 is shown as one possibleimplementation of the present embodiments. The security system 400includes a hardware processor 402 and a memory 404. One or more sensors406 provide data about a monitored area to the security system 400. Thesensors 406 may include, for example, a camera, a night vision camera(e.g., operating in infrared), door and window sensors, acousticsensors, temperature sensors, and any other sensors that collect rawdata regarding the monitored area.

The CNN system 300 is included in the security system 400. The CNNsystem 300 accepts information that is gathered by the sensors 406 andstored in memory 404, outputting security status information. The CNNsystem 300 may include its own separate processor 302 and memory 304 ormay, alternatively, omit those feature in favor of using the processor402 and memory 404 of the security system 400.

An alert module 408 accepts the output of the CNN system 300. The alertmodule 408 determines if the state of the area being monitored haschanged and, if so, whether an alert should be issued. For example, theCNN system 300 may detect movement or the presence of a person or objectin a place where it does not belong. Alternatively, the CNN system 300may detect an intrusion event. In such a situation, the alert module 408provides an appropriate alert to one or more of the user and a responseorganization (e.g., medical, police, or fire). The alert module 408provide the alert by any appropriate communications mechanism, includingby wired or wireless network connections or by a user interface.

A control module 410 works with the alert module 408 to performappropriate security management actions. For example, if an unauthorizedperson is detected by the CNN system 300, the control module 410 mayautomatically increase a security level and perform such actions aslocking doors, increasing sensor sensitivity, and changing thesensitivity of the alert module 408.

Because the CNN system 300 has been pruned, the CNN system 300 canprovide accurate results with relatively low computational complexity,making it possible to implement the security system 400 on lower-powerhardware. In particular, the processor 402 need not be a high-powereddevice and may in particular be implemented in an embedded environment.

The foregoing is to be understood as being in every respect illustrativeand exemplary, but not restrictive, and the scope of the inventiondisclosed herein is not to be determined from the Detailed Description,but rather from the claims as interpreted according to the full breadthpermitted by the patent laws. It is to be understood that theembodiments shown and described herein are only illustrative of theprinciples of the present invention and that those skilled in the artmay implement various modifications without departing from the scope andspirit of the invention. Those skilled in the art could implementvarious other feature combinations without departing from the scope andspirit of the invention. Having thus described aspects of the invention,with the details and particularity required by the patent laws, what isclaimed and desired protected by Letters Patent is set forth in theappended claims.

What is claimed is:
 1. A method for pruning a convolutional neural network (CNN), comprising: calculating a sum of kernel weights of each of a plurality of filters in a layer of the CNN; sorting the plurality of filters in the layer by respective sums of weights; pruning m filters with the smallest sums of weights to decrease a computational cost of operating the CNN; and retraining the pruned CNN to repair accuracy loss that results from pruning the m filters by creating a new kernel layer matrix for the layer and copying un-pruned kernel weights to the new kernel matrix.
 2. The method of claim 1, further comprising pruning feature maps corresponding to the m pruned filters.
 3. The method of claim 2, pruning kernels in a subsequent layer that correspond to the pruned feature maps.
 4. The method of claim 1, further comprising iterating the steps of pruning and retraining until a threshold CNN accuracy is reached.
 5. The method of claim 1, further comprising selecting a number of filters m based on a sensitivity of the layer to pruning.
 6. The method of claim 5, wherein a smaller m is selected for layers that have relatively high sensitivities compared to layers that have relatively low sensitivities.
 7. The method of claim 5, wherein sensitivity to pruning is measured as a degree of accuracy change.
 8. A method for pruning a convolutional neural network (CNN), comprising: calculating a sum of kernel weights of each of a plurality of filters in a layer of the CNN; sorting the plurality of filters in the layer by respective sums of weights; selecting a number of filters m based on a sensitivity of the layer to pruning, measured as a degree of accuracy change; pruning m filters with the smallest sums of weights to decrease a computational cost of operating the CNN; pruning feature maps corresponding to the m pruned filters; pruning kernels in a subsequent layer that correspond to the pruned feature maps; and retraining the pruned CNN to repair accuracy loss that results from pruning the m filters by creating a new kernel layer matrix for the layer and copying un-pruned kernel weights to the new kernel matrix.
 9. A system for pruning a convolutional neural network (CNN), comprising: a hardware processor; and a memory, configured to store computer program code that, when executed by the hardware processor, is configured to execute: a pruning module configured to calculate a sum of kernel weights of each of a plurality of filters in a layer of the CNN, to sort the plurality of filters in the layer by respective sums of weights, and to prune m filters with the smallest sums of weights to decrease a computational cost of operating the CNN; and a training module configured to retrain the pruned CNN to repair accuracy loss that results from pruning the m filters by creating a new kernel layer matrix for the layer and copying un-pruned kernel weights to the new kernel matrix.
 10. The system of claim 9, wherein the pruning module is further configured to prune feature maps corresponding to the m pruned filters.
 11. The system of claim 10, wherein the pruning module is further configured to prune kernels in a subsequent layer that correspond to the pruned feature maps.
 12. The system of claim 9, wherein the pruning module and the training module are further configured to iterate the steps of pruning and retraining until a threshold CNN accuracy is reached.
 13. The system of claim 9, wherein the pruning module is further configured to select a number of filters m based on a sensitivity of the layer to pruning.
 14. The system of claim 13, wherein a smaller m is selected for layers that have relatively high sensitivities compared to layers that have relatively low sensitivities.
 15. The system of claim 13, wherein sensitivity to pruning is measured as a degree of accuracy change. 